package com.lzx.iteam.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.lzx.iteam.AttendanceCalendarActivity;
import com.lzx.iteam.AttendanceDeviceErrorActivity;
import com.lzx.iteam.BaiduMapSearchActivity;
import com.lzx.iteam.R;
import com.lzx.iteam.bean.AddressData;
import com.lzx.iteam.bean.AttendanceCalendarMsgData;
import com.lzx.iteam.util.DateUtil;

import java.util.ArrayList;
import java.util.List;

import static android.R.attr.text;

/**
 * Created by Megan on 16/9/2.
 */
public class LegworkAddressListAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<AddressData> mAddressDatas = new ArrayList<AddressData>();

    public LegworkAddressListAdapter(Context context) {
        this.mContext = context;
    }

    public void bindData(ArrayList<AddressData> addressDatas) {
        this.mAddressDatas = addressDatas;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return mAddressDatas == null ? 0 : mAddressDatas.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return mAddressDatas == null ? null : mAddressDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_legwork_map_list,
                    parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.name.setText(mAddressDatas.get(position).getName());
        holder.address.setText(mAddressDatas.get(position).getAddress());

        return convertView;
    }

    class ViewHolder {
        public TextView name;
        public TextView address;

        public ViewHolder(View view) {
            name = (TextView) view.findViewById(R.id.tv_legwork_map_name);
            address = (TextView) view.findViewById(R.id.tv_legwork_map_address);
        }
    }
}
